package com.xmkj.bearbiz.home;

import android.content.Intent;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.common.Entity.SortEntity;
import com.common.mvp.BaseMvpActivity;
import com.common.mvp.BasePresenter;
import com.common.retrofit.method.GetSortDatasMethods;
import com.common.retrofit.subscriber.CommonSubscriber;
import com.common.retrofit.subscriber.SubscriberListener;
import com.xmkj.bearbiz.R;

/**
 * Create by leo
 * 创建日期：2018/5/15
 * 描述：
 */

public class SortActivity extends BaseMvpActivity implements SortTabAdapter.ClickListener {
    RecyclerView recyclerView ;
    private SortTabAdapter sortTabAdapter;
    private SortEntity sortEntity;

    @Override
    protected BasePresenter createPresenterInstance() {
        return null;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_sort;
    }

    @Override
    protected void onViewCreated() {
        recyclerView    = findViewById( R.id.recyclerview) ;

    }

    @Override
    protected void doLogicFunc() {
            getDatas();
    }

    private void getDatas() {
        showProgressingDialog();
        CommonSubscriber<SortEntity> subscriber = new CommonSubscriber<>(new SubscriberListener() {
            @Override
            public void onNext(Object o) {
                dismissProgressDialog();

                sortEntity = (SortEntity) o;
                initOrginReclerview(sortEntity);

            }

            @Override
            public void onError(String e, int code) {
                dismissProgressDialog();
                showToastMsg(e);
            }
        });


        GetSortDatasMethods.getInstance().goodCategory(subscriber, uid,hashid);
        rxManager.add(subscriber);
    }
    private void initOrginReclerview( SortEntity sortEntity ) {
        GridLayoutManager layoutManager = new GridLayoutManager(context, 3);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(layoutManager);
        sortTabAdapter = new SortTabAdapter(context, sortEntity.lists);
        recyclerView.setAdapter(sortTabAdapter);
        sortTabAdapter.setItemClick(this);
    }
    @Override
    protected void setNavigation() {
        setNavigationBack("分类");
    }

    @Override
    public void click(int position) {
        Intent intent = new Intent(context,FenLeiListActivity.class);
        intent.putExtra(FenLeiListActivity.BEAN,sortEntity.lists.get(position));
        startActivity(intent);
    }
}
